<template>
  <div class="echarts-box">
    <div id="skillpicture" :style="{ width: '900px', height: '300px' }"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import {ref, onMounted, onUpdated, watchEffect, watch} from "vue";
export default {
  props:{
    skillMapDtoList: {
      type: Array,
      required: true
    }
  },

  setup(props) {
    const skillMapDtoList=ref(props.skillMapDtoList)
    console.log(skillMapDtoList,'skill6666嘤嘤嘤嘤嘤嘤嘤嘤嘤嘤嘤嘤')
    watch(skillMapDtoList, (newValue, oldValue) => {
      console.log("skillMapDtoList 变化： ",oldValue, "->", newValue)
    });
    onMounted(() => {
      initChart();
    });
    function initChart() {
      const yAxisData = skillMapDtoList.value.map(item => item.tagName);
      const seriesData = skillMapDtoList.value.map(item => ({
        value: item.score * 100
      }))
      //雷达图
      let chart = echarts.init(document.getElementById("skillpicture"));
      chart.setOption({
        xAxis: {
          type: "value",
          min: 0,
          max: 100,
        },
        yAxis: {
          type: "category",
          data: yAxisData,
        },
        series: [
          {
            data: seriesData,
            type: "bar",
            legendHoverLink: true,
            label: {
              show: true,
              position: 'insideRight', // 柱状图上显示具体数值的位置
              formatter: '{c}%' // 显示百分比
            }
          },
        ],
      });

      window.onresize = () => {
        //自适应大小
        chart.resize();
      };
    }
    return { initChart,skillMapDtoList };
  },
};
</script>

<style scoped>
</style>